<?php

session_start();

if(isset($_SESSION['loggedin'])){
	include 'adminfunc.php';
	include '../func/sql.php';

	
	
	if(isset($_POST['name']) && isset($_POST['info']) && isset($_POST['max']) && isset($_POST['date'])){
		
		$name = $_POST['name'];
		$info = nl2br($_POST['info']);
		$max = intval($_POST['max']);
		$date = strtotime($_POST['date']);
		
		if(strlen($name) != 0 && strlen($info) != 0 && strlen((string)$max) != 0 && strlen((string)$date) != 0){
			
			$id = addEvent($name,$info,$max,$date);
			
			$_SESSION['msg'] = "<p>SUCCESSFULLY ADDED NEW EVENT!!</p>";
			header("Location: index.php?event=" . $id);
		}else{
			$_SESSION['info'] = $info;
			$_SESSION['max'] = $max;
			$_SESSION['name'] = $name;
			header("Location: index.php?newevent&err");
		}
		
		
	}
	
}else{
	header("Location: index.php");
}

?>
